import datetime

from model import Log as Log


def create_log(process_id, ip, port, project_id, project_name):
    _res = Log.Log.insert(
        process_id=process_id,
        ip=ip,
        port=port,
        project_id=project_id,
        project_name=project_name,
        start_time=datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
        end_time=datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
    ).execute()
    return _res


def update_log_end_time(log_id):
    Log.Log.update({
        Log.Log.end_time: datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
    }).where(
        Log.Log.id == log_id
    ).execute()
